package com.woniuedu.controller;

import com.woniuedu.commonutils.R;
import com.woniuedu.server.VodService;
import com.woniuedu.server.impl.VodServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 视频相关操作
 * @Author：向天浩
 * @Date：2022/4/18 10:09
 * @Description :TODO
 */
@RestController
@RequestMapping("/video")
public class VodController {

    @Autowired
    VodService vodService;

    /**
     *功能描述 上传视频
     * @Author: 向天浩
     * @Date: 2022/4/19 9:45
     * @param file
     * @return java.lang.String
     */
    @PostMapping("/upload")
    public R videoupload(MultipartFile file){
        String videoId = vodService.uploadAlyVideo(file);
        return R.ok().data("videoId",videoId);
    }


    /**
     *功能描述 删除视频
     * @Author: 向天浩
     * @Date: 2022/4/19 10:10
     * @param videoId
     * @return void
     */
    @GetMapping("/remove/{id}")
    public R removeVideo(@PathVariable("id") String videoId){
        System.out.println(videoId);
        vodService.removeVideo(videoId);
        return R.ok();
    }

    /**
     *功能描述 批量删除
     * @Author: 向天浩
     * @Date: 2022/4/27 16:47
     * @param videoList
     * @return com.woniuedu.commonutils.R
     */
    @PostMapping("/removes")
    public R removeList(@RequestBody List<String> videoList){
        vodService.removelist(videoList);
        return R.ok();
    }

    /**
     *功能描述 获取播放凭证
     * @Author: 向天浩
     * @Date: 2022/4/27 16:48
     * @param videoId
     * @return com.woniuedu.commonutils.R
     */
    @GetMapping("/getAuth/{vid}")
    public R getAuth(@PathVariable("vid") String videoId){
        String playAuth=vodService.getAuth(videoId);
        return R.ok().data("playAuth",playAuth);
    }
}
